<template>
  <div class="app-container" style="margin-top: -30px">
    <h3>当日订单展示</h3>
    <el-table
      v-loading="loading"
      :data="postList"
      :model="queryParams"
      border
      style="font-size: 15px; margin-top: -20px"
      :header-cell-style="{ background: '#6eaef5', color: '#ffffff' }"
    >
      <el-table-column label="id" align="center" prop="flowid" width="40" />
      <el-table-column label="wdr号" align="center" prop="wdr" width="80" />
      <el-table-column
        label="订单编号"
        align="center"
        prop="orderNo"
        width="100"
      />
      <el-table-column
        label="零件号"
        align="center"
        prop="partNo"
        width="110"
      />
      <el-table-column label="订单描述" align="center" prop="orderDescribe" />
      <el-table-column
        label="订单数量(个)"
        align="center"
        prop="orderNum"
        width="100"
      />
      <el-table-column label="订单状态" align="center" prop="orderState" />
      <el-table-column label="合格率" align="center" prop="yield" />
      <el-table-column label="进度" align="center" prop="progress" />
      <el-table-column
        label="开始时间"
        align="center"
        prop="productTime"
        width="180"
      />
      <el-table-column
        label="结束时间"
        align="center"
        prop="endTime"
        width="180"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:edit']"
            >开始生产</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:remove']"
            >结束生产</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handledown(scope.row)"
            v-hasPermi="['system:order:down']"
            >暂停生产</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { ordercart1, setprod, finish, stop } from "@/api/system/from";
export default {
  data() {
    return {
      loading: true,
      postList: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        flowid: null,
        wdr: null,
        orderNo: null,
        partNo: null,
        orderDescribe: null,
        orderNum: null,
        orderState: null,
        progress: null,
        productTime: null,
        endTime: null,
        id: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      ordercart1(this.queryParams).then((response) => {
        this.postList = response.list;
        this.total = response.total;
        this.loading = false;
        this.postList.map((item, inde, arr) => {
          if (item.orderNo !== null) {
            if (item.orderNo.indexOf("*") !== -1) {
              item.orderNo = item.orderNo.replace(/\*/g, "\n");
            }
            if (item.orderNo.indexOf(".") !== -1) {
              item.orderNo = item.orderNo.replace(/\./g, "\n");
            }
          }
          if (item.partNo !== null) {
            if (item.partNo.indexOf("*") !== -1) {
              item.partNo = item.partNo.replace(/\*/g, "\n");
            }
            if (item.partNo.indexOf(".") !== -1) {
              item.partNo = item.partNo.replace(/\./g, "\n");
            }
          }
        });
      });
    },
    handleDelete(row) {
      const id = row.id || this.id;
      this.$modal
        .confirm("是否确认生产")
        .then(function () {
          return setprod(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("确定生产成功");
        })
        .catch(() => {});
    },
    handleUpdate(row) {
      const id = row.id || this.id;
      this.$modal
        .confirm("是否结束生产")
        .then(function () {
          return finish(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("生产完成");
        })
        .catch(() => {});
    },
    handledown(row) {
      const id = row.id || this.id;
      this.$modal
        .confirm("是否暂停生产")
        .then(function () {
          return stop(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("暂停生产完成");
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped>
h3 {
  text-align: center;
  font-size: 35px;
  color: #6280c6;
}
.app-container >>> .el-table .cell {
  white-space: pre-wrap;
}
</style>
